// import DataBus from '../libs/data.js'; // 导入参数
export default {
	render(ctx) {
		// return
		let canvas = GameGlobal.databus.canvas
		let gameokBg = GameGlobal.databus.game1image.gameokBg
		let btn3Bg = GameGlobal.databus.game1image.btn3Bg
		let btn4Bg = GameGlobal.databus.game1image.btn4Bg

		ctx.drawImage(gameokBg.value,
			canvas.width / 2 - gameokBg.box.w / 2 + gameokBg.box.x,
			canvas.height / 2 - gameokBg.box.h / 2 + gameokBg.box.y,
			gameokBg.box.w, gameokBg.box.h);

		ctx.drawImage(btn3Bg.value,
			canvas.width / 2 - btn3Bg.box.w / 2 + btn3Bg.box.x,
			canvas.height / 2 - btn3Bg.box.h / 2 + btn3Bg.box.y,
			btn3Bg.box.w, btn3Bg.box.h);

		ctx.drawImage(btn4Bg.value,
			canvas.width / 2 - btn4Bg.box.w / 2 + btn4Bg.box.x,
			canvas.height / 2 - btn4Bg.box.h / 2 + btn4Bg.box.y,
			btn4Bg.box.w, btn4Bg.box.h);
	},

	// 核心绘制方法

	// 随机圆点
	generateSpots() {
		let canvas = GameGlobal.databus.canvas
		const SPOT_RADIUS = 30; // 圆点半径
		const MIN_DISTANCE = 60; // 最小间距（两倍半径）

		// 根据需求定义生成区域（含安全边距）
		const generateArea = {
			x: 30, // X起始位置 = 0 + 半径
			y: 100 + SPOT_RADIUS, // Y起始位置 = 100 + 半径
			width: canvas.width - 60, // 宽度 = 全屏 - 两侧半径
			height: (canvas.height - 100) - SPOT_RADIUS * 2 // 高度 = 区域高度 - 底部半径
		};

		for (let i = 0; i < 5; i++) {
			let isValid = false;
			let newSpot;
			// 循环生成直到找到符合条件的点
			while (!isValid) {
				// 在限定区域内随机生成坐标（含安全边距）
				newSpot = {
					x: Math.random() * generateArea.width + generateArea.x,
					y: Math.random() * generateArea.height + generateArea.y,
					w: SPOT_RADIUS,
					h: SPOT_RADIUS * 1.6,
					r: SPOT_RADIUS,
					isClicked: false // 新增属性
				};

				// 检查边界条件（二次验证）
				isValid = (
						newSpot.x >= generateArea.x &&
						newSpot.x <= generateArea.x + generateArea.width &&
						newSpot.y >= generateArea.y &&
						newSpot.y <= generateArea.y + generateArea.height
					) &&

					// 检查与所有现有点的距离
					GameGlobal.databus.gameSpots.every(existing => {
						const dx = newSpot.x - existing.x;
						const dy = newSpot.y - existing.y;
						return Math.sqrt(dx * dx + dy * dy) >= MIN_DISTANCE;
					});
			}
			GameGlobal.databus.gameSpots.push(newSpot);
		}
	}
}